package com.example.composableexample.stateflow

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.viewmodel.compose.viewModel

/**
 * author: LiLiang
 * createTime: 2022/10/7-10:28
 * remark:
 **/

@Preview
@Composable
fun StateFlowSimple() {
    val viewModel = viewModel<StateFlowViewModel>()
    val composeColor = viewModel.composeColor
    val flowColor by viewModel.color.collectAsState()

    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color(composeColor))
            .clickable { viewModel.generateNewColor() }
    )
}